package com.creditease.rss.ui;

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.creditease.rss.util.FileUtil;

public class LoadingActity extends Activity implements AnimationListener {
    private final static String TAG = LoadingActity.class.getName();
    private ImageView imageView;
    private TextView textView;
    private Animation alphaAnimation = null;
    private String xmlString;
    private String url;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        /*
           * //设置无标题 requestWindowFeature(Window.FEATURE_NO_TITLE); //设置全屏
           * getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
           * WindowManager.LayoutParams.FLAG_FULLSCREEN);
           */
        setContentView(R.layout.loading);
        imageView = (ImageView) findViewById(R.id.imageView);

        int random = new Random().nextInt(4);
        Bitmap bitmap = FileUtil.getLoacalBitmap(getApplicationContext(), "images/loading"
                + random
                + ".jpg");
        imageView.setImageBitmap(bitmap);
        textView = (TextView) findViewById(R.id.loadingText);
        textView.setText("遇见你，遇见你是我这辈子最最温暖的事了。");

        alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.loading_alpha);
        alphaAnimation.setFillEnabled(true); // 启动Fill保持
        alphaAnimation.setFillAfter(true); // 设置动画的最后一帧是保持在View上面
        imageView.setAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(this); // 为动画设置监听


    }

    @Override
    public void onAnimationEnd(Animation animation) {
        // 动画结束时结束欢迎界面并转到软件的主界面
        Intent intent = new Intent(this, HomeActivity.class);
//		intent.putExtra("xml", xmlString);
//		intent.putExtra("url", url);
        startActivity(intent);
        this.finish();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // 在欢迎界面屏蔽BACK键
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return false;
        }
        return false;
    }

    @Override
    public void onAnimationStart(Animation animation) {}
}
